<?php
//查询队伍数据
$params = json_decode(file_get_contents("php://input"), true);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $playerName = $params['playerName'];
}

include('../mysqli_connect.php');
if ($playerName == '') {
  $sql = "select p.*,t.team_name from team t, player p where t.team_id=p.team_id and player_id<>100";
} else {
  $sql= "select p.*,t.team_name from player p,team t where t.team_id=p.team_id and (p.player_name like '%{$playerName}%' or t.team_name like '%{$playerName}%');";
}

$res = mysqli_query($dbc, $sql);
if (!$res) {
  printf("Error: %s\n", mysqli_error($dbc));
  exit();
}
if ($res) {
  // 查询成功
  $resultArray = array();
  $i = 0;
  while ($row = mysqli_fetch_row($res)) {
    // $resultArray[] = $row;
    $resultArray[$i]['playerId'] = $row[0];
    $resultArray[$i]['playerName'] = $row[1];
    $resultArray[$i]['playerDesc'] = $row[2];
    $resultArray[$i]['playerAge'] = $row[3];
    $resultArray[$i]['playerNum'] = $row[4];
    $resultArray[$i]['height'] = $row[5];
    $resultArray[$i]['playerClub'] = $row[6];
    $resultArray[$i]['playerSalary'] = $row[7];
    $resultArray[$i]['playerPos'] = $row[8];
    $resultArray[$i]['playerScore'] = $row[9];
    $resultArray[$i]['birthDate'] = $row[10];
    $resultArray[$i]['teamName'] = $row[13];
    $i = $i + 1;
  }
  $response = array('status' => true, 'message' => '查询数据成功', 'data' => $resultArray, 'sql' => $sql);
  echo json_encode($response);
} else {
  $response = array('status' => false, 'message' => '查询队伍失败', 'data' => $resultArray);
  echo json_encode($response);
}
